import dotenv from 'dotenv';
import { SystemConfig } from '../types';

dotenv.config();

export const config: SystemConfig = {
  ssh: {
    host: process.env.SSH_HOST || 'localhost',
    port: parseInt(process.env.SSH_PORT || '22'),
    username: process.env.SSH_USERNAME || 'root',
    password: process.env.SSH_PASSWORD || '',
    timeout: parseInt(process.env.SSH_TIMEOUT || '30000')
  },
  deepseek: {
    apiKey: process.env.DEEPSEEK_API_KEY || '',
    baseURL: process.env.DEEPSEEK_BASE_URL || 'https://api.deepseek.com/v1',
    model: process.env.DEEPSEEK_MODEL || 'deepseek-chat',
    maxTokens: parseInt(process.env.DEEPSEEK_MAX_TOKENS || '4096')
  },
  logLevel: process.env.LOG_LEVEL || 'info',
  sessionTimeout: parseInt(process.env.SESSION_TIMEOUT || '3600000'),
  maxCommandLength: parseInt(process.env.MAX_COMMAND_LENGTH || '1000')
};

export function validateConfig(): void {
  if (!config.deepseek.apiKey) {
    throw new Error('DEEPSEEK_API_KEY is required');
  }

  if (!config.ssh.host) {
    throw new Error('SSH_HOST is required');
  }

  if (!config.ssh.username) {
    throw new Error('SSH_USERNAME is required');
  }

  if (!config.ssh.password) {
    throw new Error('SSH_PASSWORD is required');
  }
}